<template>
  <view style="padding-bottom: 50px;" v-if="cart.length!==0">
    <!-- 收货地址 -->
    <my-address></my-address>
    <!-- 表头 -->
    <view class="cart-title-box">
      <uni-icons type="shop" size="18"></uni-icons>
      <text>购物车</text>
    </view>
    <!-- 商品列表区域 -->
    <uni-swipe-action>
      <block v-for="(goods, i) in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="deleteGoods(goods)">
          <my-goods :goods="goods" :isShowRadio="true" :isShowNum="true" @radio-change="radioHandler"
            @num-change="numHandler"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算区域 -->
    <my-settle></my-settle>
  </view>
  <view class="cart-empty" v-else>
    <image src="../../static/cart_empty@2x.png"></image>
    <text>空空如也~</text>
  </view>
</template>

<script>
  import badgeMixin from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'

  export default {
    mixins: [badgeMixin],
    data() {
      return {
        options: [{
          text: "删除",
          style: {
            backgroundColor: '#c00000' // 按钮的背景颜色
          }
        }]
      };
    },
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    onLoad() {

    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'deleteGoodsItem']),
      radioHandler(e) {
        this.updateGoodsState(e)
      },
      numHandler(e) {
        this.updateGoodsCount(e)
      },
      deleteGoods(e) {
        this.deleteGoodsItem(e.goods_id)
      },
      addressHandler() {

      }
    }
  }
</script>

<style lang="scss">
  .cart-title-box {
    height: 40px;
    display: flex;
    border-bottom: 1px solid #efefef;
    align-items: center;
    padding-left: 5px;

    text {
      font-size: 14px;
      margin-left: 10px;
    }
  }

  .cart-empty {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 150px;

    image {
      width: 90px;
      height: 90px;
    }

    text {
      font-size: 12px;
      color: gray;
      margin-top: 15px;
    }
  }
</style>
